package com.CodingInn.code.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * try{
 * 		前置通知
 *		目标方法的执行
 *		返回通知
 * }catch(){
 *		异常通知
 * }finally{
 *		后置通知
 * }
 */

@Component
@Aspect
public class LogAspect {

	public LogAspect() {
		System.out.println("LogAspect init.....");
	}

	@Before("execution(* com.CodingInn.code.aop.HelloService.sayHello(..))")
	public void logStart(JoinPoint joinPoint){
		String name = joinPoint.getSignature().getName();
		System.out.println("logStart()==>"+name+"...[args: " + Arrays.asList(joinPoint.getArgs()) + "]" );
	}

	@AfterReturning("execution(* com.CodingInn.code.aop.HelloService.sayHello(..))")
	public void logReturn(JoinPoint joinPoint){
		String name = joinPoint.getSignature().getName();
		System.out.println("logReturn()==>"+name+"...[args: " + Arrays.asList(joinPoint.getArgs()) + "]" );
	}

	@After("execution(* com.CodingInn.code.aop.HelloService.sayHello(..))")
	public void logAfter(JoinPoint joinPoint){
		String name = joinPoint.getSignature().getName();
		System.out.println("logAfter()==>"+name+"...[args: " + Arrays.asList(joinPoint.getArgs()) + "]" );
	}

	@AfterThrowing("execution(* com.CodingInn.code.aop.HelloService.sayHello(..))")
	public void AfterThrowing(JoinPoint joinPoint){
		String name = joinPoint.getSignature().getName();
		System.out.println("AfterThrowing()==>"+name+"...[args: " + Arrays.asList(joinPoint.getArgs()) + "]" );
	}
}
